package com.ruoyi.job.service.impl;

import java.util.List;

import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.job.domain.JobStudent;
import com.ruoyi.job.mapper.JobStudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.job.mapper.JobHelpMapper;
import com.ruoyi.job.domain.JobHelp;
import com.ruoyi.job.service.IJobHelpService;

/**
 * 就业帮扶Service业务层处理
 * 
 * @author LYD
 * @date 2023-01-15
 */
@Service
public class JobHelpServiceImpl implements IJobHelpService 
{
    @Autowired
    private JobHelpMapper jobHelpMapper;
    @Autowired
    private JobStudentMapper studentMapper;

    /**
     * 查询就业帮扶
     * 
     * @param id 就业帮扶主键
     * @return 就业帮扶
     */
    @Override
    public JobHelp selectJobHelpById(Long id)
    {
        return jobHelpMapper.selectJobHelpById(id);
    }

    /**
     * 查询就业帮扶列表
     * 
     * @param jobHelp 就业帮扶
     * @return 就业帮扶
     */
    @Override
    public List<JobHelp> selectJobHelpList(JobHelp jobHelp)
    {
        return jobHelpMapper.selectJobHelpList(jobHelp);
    }

    /**
     * 新增就业帮扶
     * 
     * @param jobHelp 就业帮扶
     * @return 结果
     */
    @Override
    public int insertJobHelp(JobHelp jobHelp)
    {
        return jobHelpMapper.insertJobHelp(jobHelp);
    }

    /**
     * 修改就业帮扶
     * 
     * @param jobHelp 就业帮扶
     * @return 结果
     */
    @Override
    public int updateJobHelp(JobHelp jobHelp) {


        //修改学生管理中的状态
        String phone = jobHelp.getPhone();
        String note = jobHelp.getNote();
        JobStudent student = studentMapper.findByPhone(phone,note);
        //存在
        if (student!=null){
          student.setState(jobHelp.getState());
            studentMapper.updateJobStudent(student);
        }else {
            throw new BaseException("该帮扶学员的信息不存在或已被删除");
        }

        //父类修改帮扶信息
        return jobHelpMapper.updateJobHelp(jobHelp);
    }

    /**
     * 批量删除就业帮扶
     * 
     * @param ids 需要删除的就业帮扶主键
     * @return 结果
     */
    @Override
    public int deleteJobHelpByIds(Long[] ids)
    {
        return jobHelpMapper.deleteJobHelpByIds(ids);
    }

    /**
     * 删除就业帮扶信息
     * 
     * @param id 就业帮扶主键
     * @return 结果
     */
    @Override
    public int deleteJobHelpById(Long id)
    {
        return jobHelpMapper.deleteJobHelpById(id);
    }
}
